﻿using System;
using Kaleida.ServiceMonitor.Model;
using NUnit.Framework;

namespace Kaleida.UnitTests.Model
{
    [TestFixture]
    public class DateTimeExtensionsTests
    {
        [Test]
        public void TestToRelative()
        {
            Assert.AreEqual("99 days ago", new TimeSpan(-99, 00, 00, 00).ToRelative());
            Assert.AreEqual("2 days ago", new TimeSpan(-2, 00, 00, 00).ToRelative());
            Assert.AreEqual("25 hours ago", new TimeSpan(-1, -01, 00, 00).ToRelative());
            Assert.AreEqual("23 hours ago", new TimeSpan(-23, 00, 00).ToRelative());
            Assert.AreEqual("2 hours ago", new TimeSpan(-2, 00, 00).ToRelative());
            Assert.AreEqual("90 minutes ago", new TimeSpan(-1, -30, 00).ToRelative());
            Assert.AreEqual("59 minutes ago", new TimeSpan(0, -59, 00).ToRelative());
            Assert.AreEqual("4 minutes ago", new TimeSpan(0, -4, 00).ToRelative());
            Assert.AreEqual("2 minutes ago", new TimeSpan(0, -2, -05).ToRelative());
            Assert.AreEqual("2 minutes ago", new TimeSpan(0, -2, 00).ToRelative());
            Assert.AreEqual("30 seconds ago", new TimeSpan(0, 0, -30).ToRelative());
            Assert.AreEqual("2 seconds ago", new TimeSpan(0, 0, -2).ToRelative());

            Assert.AreEqual("about now", new TimeSpan(0, 0, -1).ToRelative());
            Assert.AreEqual("about now", new TimeSpan(0, 0, 0).ToRelative());
            Assert.AreEqual("about now", new TimeSpan(0, 0, 1).ToRelative());

            Assert.AreEqual("in 2 seconds", new TimeSpan(0, 0, 2).ToRelative());
            Assert.AreEqual("in 30 seconds", new TimeSpan(0, 0, 30).ToRelative());
            Assert.AreEqual("in 2 minutes", new TimeSpan(0, 2, 00).ToRelative());
            Assert.AreEqual("in 2 minutes", new TimeSpan(0, 2, 05).ToRelative());
            Assert.AreEqual("in 4 minutes", new TimeSpan(0, 4, 00).ToRelative());
            Assert.AreEqual("in 59 minutes", new TimeSpan(0, 59, 00).ToRelative());
            Assert.AreEqual("in 90 minutes", new TimeSpan(1, 30, 00).ToRelative());
            Assert.AreEqual("in 2 hours", new TimeSpan(2, 00, 00).ToRelative());
            Assert.AreEqual("in 23 hours", new TimeSpan(23, 00, 00).ToRelative());
            Assert.AreEqual("in 25 hours", new TimeSpan(1, 01, 00, 00).ToRelative());
            Assert.AreEqual("in 2 days", new TimeSpan(2, 00, 00, 00).ToRelative());
            Assert.AreEqual("in 99 days", new TimeSpan(99, 00, 00, 00).ToRelative());
        }
    }
}
